package com.thinkcoder.signutil;

import com.thinkcoder.exception.ServiceException;

import java.security.MessageDigest;

public class MD5Util {
    public static String md5(String content){
        StringBuffer sb = new StringBuffer();
        try{
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(content.getBytes("UTF-8"));


            byte[] tmpFolder = md5.digest();
            for (byte aTmpFolder : tmpFolder) {
                sb.append(Integer.toString((aTmpFolder & 0xff) + 0x100, 16).substring(1));
            }
            return sb.toString();
        }catch (Exception ex){
            throw new ServiceException(500,"md5加密失败");
        }
    }
}
